/**
 * @typedef {'TINYINT'|'SMALLINT'|'MEDIUMINT'|'INT'|'BIGINT'|'FLOAT'|'DOUBLE'|'DECIMAL'|'BIT'|'BOOL'|'BOOLEAN'|'SERIAL'|
 * 'TINYTEXT'|'TEXT'|'MEDIUMTEXT'|'LONGTEXT'|'TINYBLOB'|'BLOB'|'MEDIUMBLOB'|'LONGBLOB'|'CHAR'|'VARCHAR'|'BINARY'|
 * 'VARBINARY'|'ENUM'|'SET'|'DATE'|'DATETIME'|'TIMESTAMP'|'TIME'|'YEAR'|'JSON'|'GEOMETRY'|'POINT'|'LINESTRING'|'POLYGON'|
 * 'GEOMETRYCOLLECTION'|'MULTIPOINT'|'MULTILINESTRING'|'MULTIPOLYGON'|'NULL'} typeValue
 */

/**
 * @typedef {Object.<string, typeValue>} Columns
 */

/**
 * @param {import("mysql2").Connection} connection
 * @param {String} table name
 * @param {Columns} options
 */
export default function createTable(connection, table, options) {
    return new Promise((resolve, reject) => {
        const optionsInMysql = Object.keys(options).map(key => `${'`'}${key}${'`'} ${options[key]}`).join(',')
        connection.query(`CREATE TABLE IF NOT EXISTS ${'`'}${table}${'`'} (${optionsInMysql})`, function (err, results, fields) {
            if (err) reject(err)
            resolve(results)
        })
    })
}